/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wh.server;

import java.io.DataInput;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import wh.Player;

/**
 *
 * @author Dave
 */
public class Table extends ServerHelper {
    short tableId;
		boolean running = false;
    
    public Table(HashMap<Integer, Method> funct, int maxConn) {
        super(funct, maxConn);
        tableId = 0;
				running = true;
    }
    
    public Table(HashMap<Integer, Method> funct, int maxConn, short id) {
    	this(funct, maxConn);
    	tableId = id;
    }

    @Override
    public void run() {
	while(running) {
            for(Player p : list) {
		System.out.println("Attempting to poll player");
 	        DataInput stream = p.getReader().getDataInput();
 	        try {
                   //System.out.println(stream.readByte());
                    //((Method) functions.get(0)).invoke(null, p);
                     //System.out.println("Get successful");
                    ((Method) functions.get(new Integer(stream.readByte()))).invoke(null, p);
                    System.out.println("Invoke successful");
 	        } catch (IOException ex) {
 	               Logger.getLogger(Table.class.getName()).log(Level.SEVERE, null, ex);
 	        } catch (IllegalAccessException ex) {
 	               Logger.getLogger(Table.class.getName()).log(Level.SEVERE, null, ex);
 	        } catch (IllegalArgumentException ex) {
 	               Logger.getLogger(Table.class.getName()).log(Level.SEVERE, null, ex);
 	        } catch (InvocationTargetException ex) {
 	               Logger.getLogger(Table.class.getName()).log(Level.SEVERE, null, ex);
 	        }
 	    }
            try {
                Thread.sleep(SLEEP);
            } catch (InterruptedException ex) {
                Logger.getLogger(Table.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
